﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using FangDuShi_API.DBUtility;
using System.Data;

namespace FangDuShi_API.DAL
{
    /// <summary>
    /// 中介公司 数据类
    /// </summary>
    public class Agency
    {
        public Agency()
        { }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public FangDuShi_API.Model.Agency DataRowToModel(DataRow row)
        {
            FangDuShi_API.Model.Agency model = new FangDuShi_API.Model.Agency();
            if (row != null)
            {
                if (row["FAgencyID"] != null && row["FAgencyID"].ToString() != "")
                {
                    model.FAgencyID = decimal.Parse(row["FAgencyID"].ToString());
                }
                if (row["FDistrictNo"] != null)
                {
                    model.FDistrictNo = row["FDistrictNo"].ToString();
                }
                if (row["FAgencyName"] != null)
                {
                    model.FAgencyName = row["FAgencyName"].ToString();
                }
                if (row["FAgencyBriefName"] != null)
                {
                    model.FAgencyBriefName = row["FAgencyBriefName"].ToString();
                }
                if (row["FBusinessLicenseNo"] != null)
                {
                    model.FBusinessLicenseNo = row["FBusinessLicenseNo"].ToString();
                }
                if (row["FBusinessLicenseFile"] != null)
                {
                    model.FBusinessLicenseFile = row["FBusinessLicenseFile"].ToString();
                }
                if (row["FICNo"] != null)
                {
                    model.FICNo = row["FICNo"].ToString();
                }
                if (row["FICFile"] != null)
                {
                    model.FICFile = row["FICFile"].ToString();
                }
                if (row["FDispSeq"] != null && row["FDispSeq"].ToString() != "")
                {
                    model.FDispSeq = int.Parse(row["FDispSeq"].ToString());
                }
            }
            return model;
        }

        /// <summary>
        /// 获得地区的中介公司列表
        /// </summary>
        public DataSet GetList(string districtNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FAgencyID,FDistrictNo,FAgencyName,FAgencyBriefName,FBusinessLicenseNo,FBusinessLicenseFile,FICNo,FICFile,FDispSeq ");
            strSql.Append(" FROM t_Agency ");
            strSql.Append(" WHERE FDistrictNo=@FDistrictNo");
            
            SqlParameter[] parameters = {
					new SqlParameter("@FDistrictNo", SqlDbType.NVarChar,10)
			};
            parameters[0].Value = districtNo;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }
    }
}
